package graph.group.zhangtao.guider.homepage.activities;


import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.view.Menu;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;

import graph.group.zhangtao.guider.R;
import graph.group.zhangtao.guider.homepage.fragments.HomePageFragment;
import graph.group.zhangtao.guider.homepage.fragments.ProfileFragment;
import graph.group.zhangtao.guider.homepage.fragments.SelectionFragment;

/**
 * Created by T5 on 2016/6/16.
 */
public class HomePageActivity extends BaseActivity {
    private RadioButton rbSelection;
    private RadioButton rbProfile;
    private RadioButton rbNews;
    private FrameLayout flContainer;
    private RadioGroup rgTab;
    private FragmentTabHost tabHost;
    private Class fragment [];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getToolbar().setDisplayHomeAsUpEnabled(false).setTitle("Citi_Cup").setSubTitle("");
        fragment = new Class[]{SelectionFragment.class, HomePageFragment.class, ProfileFragment.class};
        initialize();
    }

    @Override
    public int getLayoutId() {
        return R.layout.homepage_layout;
    }

    private void initialize(){
        rbSelection = findViewById(R.id.rb_selection);
        rbProfile = findViewById(R.id.rb_profile);
        rbNews = findViewById(R.id.rb_news);
        tabHost = findViewById(R.id.tabHost);
        rgTab = findViewById(R.id.rgTab);
        flContainer = findViewById(R.id.flContainer);

        tabHost.setup(getApplicationContext(),getSupportFragmentManager(),R.id.flContainer);
        for (int i = 0;i<fragment.length;i++){
            TabHost.TabSpec tabSpec = tabHost.newTabSpec(String.valueOf(i)).setIndicator(String.valueOf(i));
            tabHost.addTab(tabSpec,fragment[i],null);
        }

        tabHost.setCurrentTab(1);
        rgTab.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_selection:
                        tabHost.setCurrentTab(0);
                        break;
                    case R.id.rb_news:
                        tabHost.setCurrentTab(1);
                        break;
                    case R.id.rb_profile:
                        tabHost.setCurrentTab(2);
                        break;
                }
            }
        });


    }


}
